<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     default_iphone
 * @copyright   Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/**
 * Product view template
 *
 * @see Mage_Catalog_Block_Product_View
 * @see Mage_Review_Block_Product_View
 */
?>
<?php 
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct(); 
$_categoryMod = Mage::getModel('catalog/category');

$brandId = $_product->getBrand();
$productId = $_product->getId();
$sameBrandProducts = Mage::getResourceModel('catalog/product_collection')
                        ->addAttributeToSelect('*')
                        ->addAttributeToFilter('visibility', array('neq' => 1))
                        ->addAttributeToFilter('status', 1)
                        ->addAttributeToFilter('entity_id', array('neq' => $productId))
                        ->addAttributeToFilter('brand',$brandId)
                        ->setCurPage(1)
                        ->setPageSize(4);
Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->sameBrandProducts);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($sameBrandProducts);
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($sameBrandProducts);

//Mage::log($_product->getData(),null,'product.log');

?>
<script type="text/javascript">
    var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->toHtml() ?></div>
<div class="product-view">
    <form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
        <?php echo $this->getBlockHtml('formkey') ?>
        <div class="no-display">
            <input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
            <input type="hidden" name="related_product" id="related-products-field" value="" />
        </div>
        <div class="product-essential">

            <div class="product-img-box">
                <?php echo $this->getChildHtml('media') ?>
            </div>

            <div class="product-shop">
                <div class="product-main-info">
                    <div class="product-name">
                        <h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
                    </div>
                    <?php 
                        $tags = Mage::helper('zgb')->getProductInfoTags($_product);
                        if($tags):
                    ?>
                    <div class="product-info-tags-wrapper">
                    <?php foreach($tags as $tag):?>
                        <span class="product-info-tags" ><?php echo $tag; ?></span>
                    <?php endforeach; ?>
                    </div>
                    <?php endif; ?>
                    <?php $promotion =  $_product->getData('promotion'); ?>
                    <?php if($promotion): ?>
                        <div class="promotion-information">
                            <p><?php echo $promotion ?></p>
                        </div>
                    <?php endif; ?>
                    <?php echo $this->getChildHtml('alert_urls') ?>
                    <?php echo $this->getChildHtml('product_type_data') ?>
                </div>
                <?php echo $this->getTierPriceHtml() ?>
                <?php echo $this->getChildHtml('extrahint') ?>

                <?php if (!$this->hasOptions()):?>
                    <?php echo $this->getChildHtml('extra_buttons') ?>
                <?php else:?>
                    <?php if ($_product->isSaleable() && $this->hasOptions() && $this->getChildChildHtml('container1') ):?>

                    <?php endif;?>
                <?php endif; ?>

                <?php echo $this->getChildHtml('other');?>
            </div>

        </div>

        <div class="product-collateral">
            <?php echo $this->getChildHtml('addtocart') ?>
                <div class="box-collateral <?php echo "box-{$alias}"?>">
                    <!--规格和添加到购物车-->
                        <div class="product-add-to">
                          <!-- 添加到收藏-->
                          <?php echo $this->getChildHtml('addto') ?>
                      </div>
              </div>

              <div class="The-customer-evaluation">
               <ul>
                   <li id="details-Click"><span><?php echo $this->__('商品详情') ?></span><i class="fa fa-angle-right"></i></li>
               </ul>
               <div class="Goods-details-2columns">
                <div class="Goods-details-1chunk">
                    <div class="Graphic-details">
                        <div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
                    </div>
                </div>
            </div>
            <?php if(count($sameBrandProducts)>0): ?>
            <div class="same-brand">
                <div class="brand-title"><h2>同品牌推荐</h2></div>
                <div class="brand-content clearfix">
                    <?php foreach($sameBrandProducts as $product): ?>
                        <div class="brand-product">
                        <div>
                            <a href="<?php echo $product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($product, 'small_image'), null, true) ?>">
                                <div class="product-image">
                                    <img src="<?php echo $this->helper('catalog/image')->init($product, 'small_image'); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($product, 'small_image'), null, true) ?>" />
                                </div>
                            </a>
                        </div>
                        <div class="product-shop">
                            <div>
                                <a href="<?php echo $product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($product, 'small_image'), null, true) ?>">
                                    <p><?php echo $_helper->productAttribute($product, $product->getName(), 'name') ?></p>
                                </a>
                                <?php echo $this->getPriceHtml($product, true) ?>
                            </div>
                        </div>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
            <?php endif; ?>
        </div>
   </div>
   <?php if ($_product->isSaleable() && $this->hasOptions() && $this->getChildChildHtml('container2') ):?>
    <div class="options-container-big">
        <?php echo $this->getChildChildHtml('container2', '', true, true) ?>
    </div>
<?php endif;?>
</form>
</div>
<script type="text/javascript">
//<![CDATA[

jQuery(function(){
    var counterLeft = (jQuery(".carousel-wrap").width()-jQuery(".counter").width())/2;
    jQuery(".counter").css({"left":counterLeft});
    //jQuery(".carousel-items img").css({"height":jQuery(".carousel-items li").width()});
    jQuery('.brand-title h2').css({'top':-jQuery('.brand-title h2').height()/2});
    jQuery('.brand-product').width(jQuery('.brand-content').width()/2-1.5*parseInt(jQuery('.brand-product').css('margin-left')));
    jQuery(".main-section").css({'margin-top':jQuery("#header-Goods").height()});
})
var productAddToCartForm = new VarienForm('product_addtocart_form');

jQuery(document).ready(function(){
        ajaxAddToCart();  
})
function ajaxAddToCart(){
    $j(".add-to-carts").click(function(){
        var index = layer.open({
            type:2,
            shadeClose:false,
        });
        $j(".layermbox2 .layermcont i").css({height:"0.2rem",width:"0.2rem"});
        var action = $j(this).parent().attr('data-action');
        var qty= $j(".qtyss").val();
        $j.post(action, {'qty':qty},
            function(data){
                //console.log(data.indexOf('checkout-cart-index'));
                console.log(JSON.parse(data).message);
                if(JSON.parse(data).code == 200){
                    if(window.hasOwnProperty('demo')){
                        if(window.demo.hasOwnProperty('changeShoppingCartNumber'))
                        window.demo.changeShoppingCartNumber(JSON.parse(data).count);
                    } 
                    layer.close(index);
                    layer.open({
                        content:"已添加到购物车！",
                        style:"font-size:0.2rem;font-family: 'Microsoft YaHei', Arial, Helvetica, sans-serif;text-align:center;width:70%;",
                        time:2,
                    });
                }else{
                    layer.close(index);
                    layer.open({
                        content:"库存不足!",
                        style:"font-size:0.2rem;font-family: 'Microsoft YaHei', Arial, Helvetica, sans-serif;text-align:center;width:70%;",
                        time:2,
                    });
                }
                 $j('.layermcont').css({'line-height':'1.2rem','padding':'0'});
            })
        });
}
//]]>
</script>
